import echarts from 'echarts';
  // 饼形图
const chartPie =  {
      restrict: 'AE',
      scope: {
        headType: '@',
        type: '@',
        className: '@',
        idName: '@',
      },
      template: "<div id='{{idName}}' class='{{className}}' ></div>",
      controller: function($rootScope,$scope, $element, $attrs, $transclude) {
          var chartPieFn = function(val, options) {
            var myChart = echarts.init(document.getElementById($scope.idName)); //'index-chart-pie'
            var option = {
              tooltip: {
                trigger: 'item',
                backgroundColor: 'rgba(255,255,255,0.3)',
                formatter: "{b} {c}<br/>占比 {d}%" //{a} <br/>{b} : {c} ({d}%)
              },
              legend: { //图例组件
                show: options.legend, // * 是否显示图例
                orient: 'horizontal', //布局  横向布局
                right: 8, //图例组件离右边的距离
                itemWidth: 6, //图例标记的图形宽度
                itemHeight: 6, //图例标记的图形高度
                borderRadius: [3, 3, 0, 0],
                data: options.legendData,
                textStyle: { //图例文字的样式
                  color: "#99ffffff"
                }
              },
              series: [{
                type: 'pie',
                radius: '55%',
                center: ['50%', '50%'],
                data: val,
                label: {
                  normal: {
                    show: true,
                    color: '#fff',
                    formatter: '{b}:{c} \n占比:{d}%',
                    fontSize: 7
                  }
                },
                labelLine: {
                  normal: {
                    lineStyle: {
                      show: true,
                      color: '#fff',
                      length: 0.001
                    }
                  }
                }
              }],
              color: options.color //手动设置每个图例的颜色
            };

            myChart.setOption(option);
          }

          $scope.$emit('chartpie',chartPieFn)
      }
    }

export default chartPie;
